<template>
  <!-- 查看用户弹框 -->
  <el-dialog title="用户查看" :visible="userViewDialogVisible" @close="onClose">
    <el-form :model="userViewForm">
      <el-form-item label="用户名" :label-width="userViewFormLabelWidth">
        <el-input v-model="userViewForm.username" :readonly="true"></el-input>
      </el-form-item>
      <!-- <el-form-item label="密码" :label-width="userViewFormLabelWidth">
        <el-input v-model="userViewForm.password"></el-input>
      </el-form-item>-->
      <el-form-item label="角色" :label-width="userViewFormLabelWidth">
        <el-select v-model="roles" multiple placeholder="请选择" disabled="true">
          <el-option
            v-for="item in roleOptions"
            :key="item.id"
            :label="item.label"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" :label-width="userViewFormLabelWidth">
        <el-input v-model="userViewForm.descr" :readonly="true"></el-input>
      </el-form-item>
      <el-form-item label="创建人" :label-width="userViewFormLabelWidth">
        <el-input v-model="userViewForm.createUser" :readonly="true"></el-input>
      </el-form-item>
      <el-form-item label="创建时间" :label-width="userViewFormLabelWidth">
        <el-input v-model="userViewForm.createTime" :readonly="true"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <!-- <el-button type="primary" size="mini" @click="handleSubmit">确认</el-button> -->
      <el-button type="danger" size="mini" @click="onCancel">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import { editUser } from "@/api/user";

export default {
  name: "UserView",
  props: ["userViewDialogVisible"],
  data() {
    return {
      //   listLoading: true,
      userViewForm: {
        id: "",
        username: "",
        // password: "",
        descr: "",
        createUser:"",
        createTime:""
      },
      userViewFormLabelWidth: "100px",
      roles: [],
      roleOptions: [],
    };
  },
  methods: {
    reset() {
      this.userViewForm.id = "";
      this.userViewForm.username = "";
      // this.userViewForm.password = "";
      this.userViewForm.descr = "";
      this.userViewForm.createUser = "";
      this.userViewForm.createTime = "";
    },
    onCancel() {
      this.reset()
      this.$emit("cancel");
    },
    onClose() {
      this.reset()
      this.$emit("close");
    },
    setFormValues(record) {
      this.userViewForm.username = record.username;
      // this.userViewForm.password = record.password;
      this.userViewForm.descr = record.descr;
      this.userViewForm.id = record.id;
      this.userViewForm.createUser = record.createUser;
      this.userViewForm.createTime = record.createTime;
      this.roleOptions = (record.roleOptions && record.roleOptions.length > 0)?record.roleOptions:[];

      if (record.roleOptions && record.roleOptions.length > 0) {
        var roleArr = [];
        for (var i = 0; i < record.roleOptions.length; i++) {
          roleArr.push(record.roleOptions[i].id);
        }
        // console.log(roleArr)
        this.roles = roleArr;
      } else {
        this.roles = [];
      }

    },
  },
};
</script>
